import logging
import os
import platform
import time
from loguru import logger


def getSeparator():
    if 'Windows' in platform.system():
        separator = '\\'
    else:
        separator = '/'
    return separator


# https://cuiqingcai.com/7776.html
def new_logger(name):
    logs_dir = os.path.expanduser(".\\logs")
    log_file = os.path.join(logs_dir, "%s_%s.log" % (name, time.strftime("%Y-%m-%d", time.localtime())))
    if os.path.exists(logs_dir) and os.path.isdir(logs_dir):
        pass
    else:
        os.mkdir(logs_dir)
    # 保留2天日志；输出到文件级别为error；单文件最大10MB
    logger.add(log_file, rotation="10 MB", retention='2 days', level='ERROR', )
    return logger


logger = new_logger("client")

if __name__ == '__main__':
    logger.info('info')
